package com.sixth.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sixth.core.entity.Patient;
import com.sixth.core.entity.User;
import com.sixth.core.vo.R;
import com.sixth.system.mapper.PatientMapper;
import com.sixth.system.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: sixth-hospital-parent
 * @description:
 * @author: 李劲锋
 * @create: 2024-08-23 16:21
 **/
@Service
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientMapper patientMapper;
    @Override
    public R<Patient> selectByName(String username) {
        // 构造查询包装器
        QueryWrapper<Patient> wrapper=new QueryWrapper<>();
        // 设置查询条件：手机号等于提供的用户名
        wrapper.eq("phone",username);

        // 执行查询操作，获取查询结果
        Patient patient =  patientMapper.selectOne(wrapper);
        if(patient==null){
            return R.error("账号或密码错误");
        }
        return R.ok(patient);
    }

    @Override
    public R<Patient> PatientInfo(String phone) {
        // 构造查询包装器
        QueryWrapper<Patient> wrapper=new QueryWrapper<>();
        // 设置查询条件：手机号等于提供的用户名
        wrapper.eq("phone",phone);

        // 执行查询操作，获取查询结果
        Patient patient =  patientMapper.selectOne(wrapper);
        if(patient==null){
            return R.error("账号或密码错误");
        }
        return R.ok(patient);

    }

    @Override
    public R updatePatientInfo(Patient patient) {
        QueryWrapper<Patient> wrapper = new QueryWrapper<>();
        wrapper.eq("patient_id",patient.getPatientId());
       patientMapper.update(patient, wrapper);
        return R.ok(200);
    }
}
